package com.tao.direct;

import com.rabbitmq.client.*;
import com.utils.RabbitMQUtils;

import javax.lang.model.SourceVersion;
import java.io.IOException;

/**
 * @ClassName Consumer1
 * @Author HETAO
 * @Date 2020/5/4 22:21
 */
public class Consumer1 {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection();
        //创建通道
        Channel channel = connection.createChannel();
        //创建临时队列
        String queue = channel.queueDeclare().getQueue();
        //绑定交换机
        channel.exchangeDeclare("logs_direct", "direct", false);
        //绑定队列
        channel.queueBind(queue, "logs_direct", "info");
        channel.queueBind(queue, "logs_direct", "error");
        channel.queueBind(queue, "logs_direct", "warning");
        channel.basicConsume(queue, true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1: = " + new String(body));
            }
        });
    }
}
